<form id="dictionary-form" lay-filter="dictionary-form" class="layui-form model-form">
    <input id="dictid" name="dictid" type="hidden"/>
    <div class="layui-form-item">
        <label class="layui-form-label">字典代码</label>
        <div class="layui-input-block">
            <input id="dccode" name="dccode" placeholder="请输入字典CODE" type="text" class="layui-input" maxlength="20"
                   lay-verify="required" required/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">字典名称</label>
        <div class="layui-input-block">
            <input id="dcname" name="dcname" placeholder="请输入字典名称" type="text" class="layui-input" maxlength="20"
                   lay-verify="required" required/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">字典类型</label>
        <div class="layui-input-block">
            <input id="dctype" name="dctype" placeholder="请输入字典类型" type="text" class="layui-input" maxlength="20"
                   lay-verify="required" required/>
        </div>
    </div>
    <div class="layui-form-item model-form-footer">
        <button class="layui-btn layui-btn-primary" ew-event="closeDialog" type="button">取消</button>
        <button class="layui-btn" lay-filter="dictionary-form-submit" lay-submit>保存</button>
    </div>
</form>

<script>
    layui.use(['layer', 'admin', 'form'], function () {

        var layer = layui.layer;
        var admin = layui.admin;
        var form = layui.form;

        form.render();
        // debugger;
        // 回显titleType数据
        var titleType = admin.getTempData('dictionary');
        if (titleType) {
            form.val('dictionary-form', titleType);
        }
        // 表单提交事件
        form.on('submit(dictionary-form-submit)', function (data) {
            layer.load(2);
            // debugger;
            if (data.field.dictid != null && data.field.dictid != ''){
                admin.req('api-user/dictionary/updateDictionary', JSON.stringify(data.field), function (data) {
                    layer.closeAll('loading');
                    if (data.code == 0) {
                        layer.msg(data.msg, {icon: 1, time: 2000});
                        admin.finishPopupCenter();
                    } else {
                        layer.msg(data.msg, {icon: 2, time: 2000});
                    }
                }, 'POST');
                return false;
            } else {
                admin.req('api-user/dictionary/addDictionary', JSON.stringify(data.field), function (data) {
                    layer.closeAll('loading');
                    if (data.code == 0) {
                        layer.msg(data.msg, {icon: 1, time: 2000});
                        admin.finishPopupCenter();
                    } else {
                        layer.msg(data.msg, {icon: 2, time: 2000});
                    }
                }, 'POST');
                return false;
            }
        });


    });
</script>